package com.study.lihan.letcode.offer;

/**
 * @Author: lihan
 * @Date : 2022/9/21- 09
 * @DESCRIPTION: com.study.lihan.letcode.offe
 * 题目：输入2个int型整数，它们进行除法计算并返回商，要求不得使用乘号'*'、除号'/'及求余符号'%'。
 * 当发生溢出时，返回最大的整数值。假设除数不为0。例如，输入15和2，输出15/2的结果，即7
 * @version: 1.0
 */
public class T1 {
    public static void main(String[] args) {
        int param1 = 28;
        int param2 = 3;
        int result = param1/param2;
       System.out.println(result == getShang(param1, param2));
    }

    public static int getShang(int param1, int param2){
        if (param1 == Integer.MIN_VALUE  && param2 == -1){
            return Integer.MAX_VALUE;
        }
        int result = 0;
        int negative = 2;
        if (param1 >0){
            negative--;
            param1 = -param1;
        }
        if (param2 > 0){
            negative--;
            param2 = -param2;
        }
        while (param1 <=param2){
            int value= param2;
            int pow = 1;
            while ( value >=Integer.MIN_VALUE/2 && param1 <= value + value ){
                value +=value;
                pow += pow;
            }
            param1 -= value;
            result += pow;
        }


       result = negative ==1 ? -result:result;
        return result;
    }



}
